package com.phiyon.mytry.db;

import com.phiyon.mytry.service.DBOpenHelper;

import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

public class PersonProvider extends ContentProvider {
	private DBOpenHelper dbOpenHelper;
	private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
	private static final int PERSONS = 1;
	static {
		MATCHER.addURI("com.phiyon.mytry.providers.personprovider", 
				"person", PERSONS);
	}
	@Override
	public int delete(Uri arg0, String arg1, String[] arg2) {
		dbOpenHelper = new DBOpenHelper(this.getContext());
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		//SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
		
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
		switch (MATCHER.match(uri)){
		case PERSONS:
			long rowid = db.insert("person", "name", values);
			Uri insertUri = ContentUris.withAppendedId(uri, rowid);
			//Uri insertUri = Uri.parse("content://com.phiyon.mytry.providers.personprovider/person/" + rowid);
			return insertUri;
		default:
			throw new IllegalArgumentException("this is Unkown Uri:" + uri);
		}
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
